package com.tj.view.view;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;

import com.tj.view.tool.DisplayUtil;

/**
 * Created by Administrator on 2017/7/12 0012.
 */

public class TsCanvasView extends View{

    private static final String TAG = "TsCanvasView";
    private int windowWidth;
    private int windowHeight;

    private Paint mPaint;
    private Path mPath;

    public TsCanvasView(Context context) {
        this(context, null);
    }

    public TsCanvasView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public TsCanvasView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initData(context);
    }

    public void initData(Context context){
        windowWidth = DisplayUtil.getWindowWidth((Activity) context);
        windowHeight = DisplayUtil.getWindowHeight((Activity) context);

        mPaint = new Paint();
        mPaint.setColor(Color.RED);
        mPaint.setStyle(Paint.Style.STROKE);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        canvas.drawColor(Color.BLACK);
        canvas.drawColor(Color.parseColor("#88880000"));//蒙层
        canvas.drawCircle(200, 200, 200, mPaint);//圆
        canvas.drawRect(200,400, 500,500, mPaint);//矩形

        mPaint.setStrokeWidth(20);//点的大小
        mPaint.setStrokeCap(Paint.Cap.ROUND);//点的形状(末端点等)
        canvas.drawPoint(600,100,mPaint);

        mPaint.setStrokeWidth(40);
        mPaint.setStrokeCap(Paint.Cap.BUTT);
        canvas.drawPoint(700,100,mPaint);

        mPaint.setStrokeWidth(60);
        mPaint.setStrokeCap(Paint.Cap.SQUARE);
        canvas.drawPoint(800,100,mPaint);

        mPaint.setStyle(Paint.Style.FILL);
        mPaint.setStrokeWidth(20);
        float[] points = {0, 0, 50, 650, 50, 900, 200, 650, 200, 900, 150, 650, 150, 800};
        canvas.drawPoints(points, 2, 8, mPaint);//画多个点

//        mPaint.setStyle(Paint.Style.FILL);
//        canvas.drawOval(200, 650, 700, 1000, mPaint);//画椭圆

        mPaint.setStyle(Paint.Style.FILL); // 填充模式
        canvas.drawArc(400, 900, 1000, 1300, -110, 100, true, mPaint); // 绘制扇形?扇形的中心点在哪里？
        canvas.drawArc(400, 900, 1000, 1300, 20, 140, false, mPaint); // 绘制弧形 ???要注意
        mPaint.setStyle(Paint.Style.STROKE); // 画线模式
        canvas.drawArc(400, 900, 1000, 1300, 180, 60, false, mPaint); // 绘制不封口的弧形


//        mPath.addOval();
    }



}
